//
//  LYMainTabBarController.swift
//  Sina_Weibo2
//
//  Created by Elsevier on 16/5/11.
//  Copyright © 2016年 Yang Lu. All rights reserved.
//

import UIKit

class LYMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let composeCallBack = { () -> ()in
            print("Modal出控制器")
        }
        
        let mainTabBar = LYMainTabBar()
        
        mainTabBar.composeCallback = composeCallBack
        // self.tabBar=mainTabBar;
        setValue(mainTabBar, forKey: "tabBar")
        setupChilderViewController()
    }
    
    func setupChilderViewController() {
        
        //首页
        let homeVC = LYHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        //消息
        let messageVC = LYMessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现
        let discoveryVC = LYDiscoveryViewController()
        addChildViewController(discoveryVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = LYProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
        
//        //首页
//        let homeVC = LYHomeViewController()
//        homeVC.title = "首页"
//        homeVC.tabBarItem.image = UIImage(named: "tabbar_home")
//        self.addChildViewController(UINavigationController(rootViewController: homeVC))
//        
//        //消息Message
//        let MessageVC = LYMessageViewController()
//        MessageVC.title = "消息"
//        MessageVC.tabBarItem.image = UIImage(named: "tabbar_message_center")
//        self.addChildViewController(UINavigationController(rootViewController: MessageVC))
//        
//        //发现Discovery
//        let discoveryVC = LYDiscoveryViewController()
//        discoveryVC.title = "发现"
//        discoveryVC.tabBarItem.image = UIImage(named: "tabbar_discover")
//        self.addChildViewController(UINavigationController(rootViewController: discoveryVC))
//        
//        //我profile
//        let profileVC = LYProfileViewController()
//        profileVC.title = "我"
//        profileVC.tabBarItem.image = UIImage(named: "tabbar_profile")
//        self.addChildViewController(UINavigationController(rootViewController: profileVC))
    }
    
    func addChildViewController(controller:UIViewController,title:String,imageName:String) {
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        self.addChildViewController(UINavigationController(rootViewController: controller))
    }
    
    
}